var editing_blog_id = -1;

$("#new-blog-btn").click(function(){
		
	$("#modal-new-blog").modal({
	    backdrop:true,
	    show:true
	});
});

$(".well-blog").mouseover(function () {
	btn_id = 'btn-'+$(this).attr('id');
    $('#'+btn_id).show("fast");
});
$(".well-blog").mouseleave(function () {
	btn_id = 'btn-'+$(this).attr('id');
    $('#'+btn_id).hide("fast");
});



function show_blog_edit_madol(bname,bid){
	$('#bname-in-modal').html(bname);
	editing_blog_id = bid;
	$("#modal-edit-blog").modal({
	    backdrop:false,
	    show:true
	});
}

function add_editor(){
	name = $("#editor-name")[0].value;
	$.get("../user/get?name="+name,function(data){
		if(data=='fail'){
			$("#edit-blog-err").html("this username seems wrong~");
			$("#edit-blog-err").show();
			$("#edit-blog-err").alert();
		} else {			
			user = eval("("+data+")");
			$.post('add_editor',{
				bid:editing_blog_id,
				editor_id:user.uid,
				},
				function(data, textStatus, jqXHR){
					//window.location.reload();
					reloadMain();
				});
		}
	});
}

function delete_editor(bid,editor_id){
	$('#editor-'+bid+"-"+editor_id).hide("fast");
	$.post('delete_editor',{
			bid:bid,
			editor_id:editor_id
		},
		function(data, textStatus, jqXHR){
		;
	});
}

function create_blog(){
	if(check_input($('#blogname')[0])){
		var blogname = $("#blogname")[0].value;
		$.post(base_url+'index.php/blog/create',{
				bname:blogname
			},
			function(data, textStatus, jqXHR){
				reloadMain();
				reloadNavi();
				$('#modal-new-blog').modal('hide')
				toastr.info('创建成功!');
			});
	}
}

function check_input(input){
	var str = input.value; 
	if(str==null||str==''){
		setControlState('#bname-cg',false);
		return false;
	} else {
		setControlState('#bname-cg',true);
		return true;
	}
}

function delete_blog(bid){
	$('#well-blog-'+bid).hide("fast");
	$.post('delete',{bid:bid},function(data, textStatus, jqXHR){
		;
	});
}